package jdbc.task1;

import java.sql.Connection;
import java.sql.DriverManager;

/*
1：设计一个DbUtil类，处理相关数据库的操作，
最好用Static方法
 */
public class DbUtil_2 {      
    private static final String URL = "jdbc:mysql://localhost:3306/java82";
    private static final String USER = "root";
    private static final String PASSWORD = "1234567";

    public Connection getConnection() {
        Connection conn = null;
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            conn = DriverManager.getConnection(URL, USER, PASSWORD);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return conn;
    }

    public void close(AutoCloseable object) {
        if (object != null) {
            try {
                object.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }


}
